package code.jam.core;

import java.util.Vector;

import android.util.Log;

import my.andoird.util.r1.AndroidGlobal;
import my.andoird.util.r1.AndroidString;

import code.jam.context.JamChordProgressionContext;
import code.jam.context.JamConfigContext;
import code.jam.context.JamGlobalVolumeContext;
import code.jam.context.JamMIFContext;

public class JamParser
{
	public final static String	DEBUG_TAG				= "JamParser";

	public static final char	CR_CARRIAGE_RETURN		= '\r';					// CR
	public static final char	CR_NEW_LINE				= '\n';					// LF
	public static final char	TAB						= '\t';
	public static final char	SPACE					= ' ';

	/*
	 * for BGM MIF file
	 */
	public static final String	ARTIST_TAG				= "[artist]";
	public static final String	TITLE_TAG				= "[title]";
	public static final String	INFORMATION_TAG			= "[information]";
	public static final String	ALBUM_TAG				= "[album_cover]";
	public static final String	GENRE_TAG				= "[genre]";
	public static final String	LENGTH_TAG				= "[length]";
	public static final String	TEMPO_TAG				= "[tempo]";
	public static final String	SCALE_TAG				= "[scale]";
	public static final String	TIME_TAG				= "[time]";
	public static final String	ACCENT_TAG				= "[accent]";
	public static final String	CHORD_PROGRESSION_TAG	= "[chord progression]";

	/*
	 * for JAM configure file
	 */
	public static final String	PROJECT_TAG				= "[project]";
	public static final String	BGM_TAG					= "[bgm]";
	public static final String	PATH_TAG				= "[file path]";
	public static final String	MIF_TAG					= "[mif]";
	public static final String	GLOBAL_VOLUME			= "[global volume]";
	
	public static final String	PIANO_TAG				= "[piano]";
	public static final String	ELEC_DIST_GUITAR		= "[elec-dist-guitar]";
	public static final String	ELEC_CLEAN_GUITAR_TAG	= "[elec-clean-guitar]";
	public static final String	ANDROID_VOICE_TAG		= "[android-voice]";

	public static JamConfigContext parseJamConfig(String source)
	{
		JamConfigContext context = new JamConfigContext();

		try
		{
			Vector<String> string = AndroidString.readTextLineByLine(source);

			if (string.isEmpty())
			{
				Log.e(DEBUG_TAG, "string is empty");
				return null;
			}

			int position = 0;

			// /// [project] /////
			position = string.indexOf(PROJECT_TAG);
			if (position != -1)
			{
				context.setProject(string.get(position + 1));
			}
			else
			{
				context = null;
				Log.e(DEBUG_TAG, "project is null");
			}

			// /// [bgm] /////
			position = string.indexOf(BGM_TAG);
			if (position != -1)
			{
				Vector<String> vector = new Vector<String>();

				for (int i = 1;; i++)
				{
					if ((position + i) > string.size()-1)
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					vector.add(string.get(position + i));
				}

				context.setBGM(vector);
			}
			else
			{
				context = null;
				Log.e(DEBUG_TAG, "bgm is null");

			}

			// /// [mif] /////
			position = string.indexOf(MIF_TAG);
			if (position != -1)
			{
				Vector<String> vector = new Vector<String>();

				for (int i = 1;; i++)
				{
					if ((position + i) > string.size()-1)
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					vector.add(string.get(position + i));
				}

				context.setMIF(vector);
			}
			else
			{
				context = null;
				Log.e(DEBUG_TAG, "mif is null");

			}

			// // [piano] ////
			position = string.indexOf(PIANO_TAG);
			if (position != -1)
			{
				Vector<String> piano_vector = new Vector<String>();

				for (int i = 1;; i++)
				{
					if ((position + i) > string.size()-1)
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					String str = string.get(position + i);

					if (str != null)
						piano_vector.add(str);
					else
						break;
				}

				context.setPiano(piano_vector);
			}
			else
			{
				context = null;
				Log.e(DEBUG_TAG, "piano is null");

			}

			// /// [android-voice] /////
			position = string.indexOf(ANDROID_VOICE_TAG);
			if (position != -1)
			{
				Vector<String> vector = new Vector<String>();

				for (int i = 1;; i++)
				{
					if ((position + i) > string.size()-1)
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					String str = string.get(position + i);

					if (str != null)
						vector.add(str);
					else
						break;
				}

				context.setAndroidVoice(vector);
			}
			else
			{
				context = null;
				Log.e(DEBUG_TAG, "android voice is failed");

			}

			// /// [elec-clean-guitar] /////
			position = string.indexOf(ELEC_CLEAN_GUITAR_TAG);
			if (position != -1)
			{
				Vector<String> elec_bass_vector = new Vector<String>();

				for (int i = 1;; i++)
				{
					if ((position + i) > string.size()-1)
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					String str = string.get(position + i);

					if (str != null)
						elec_bass_vector.add(str);
					else
						break;
				}

				context.setElecCleanGuitar(elec_bass_vector);
			}
			else
			{
				context = null;
				Log.e(DEBUG_TAG, "elec clean guitar is null");

			}

			// [elec-dist-guitar] //
			position = string.indexOf(ELEC_DIST_GUITAR);
			if (position != -1)
			{
				Vector<String> elec_dist_guitar = new Vector<String>();

				for (int i = 1;; i++)
				{
					if ((position + i) > string.size()-1)
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					String str = string.get(position + i);

					if (str != null)
					{
						elec_dist_guitar.add(str);
					}
					else
					{
						break;
					}
				}

				context.setElecDistGuitar(elec_dist_guitar);
			}
			else
			{
				context = null;
				Log.e(DEBUG_TAG, "elec dist guitar is null");
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			Log.e(DEBUG_TAG, "can't parse Jam config file");
		}

		return context;
	}

	static public JamMIFContext parseMIF(String source)
	{
		JamMIFContext mif_context = new JamMIFContext();

		StringBuilder time = new StringBuilder();

		StringBuilder chord = new StringBuilder();

		Vector<String> string = AndroidString.readTextLineByLine(source);

		try
		{
			int position = 0;

			// /// [artist] /////
			position = string.indexOf(ARTIST_TAG);
			if (position != -1)
			{
				mif_context.setArtist(string.get(position + 1));
			}
			else
			{
				mif_context = null;
			}

			// /// [title] /////
			position = string.indexOf(TITLE_TAG);
			if (position != -1)
			{
				mif_context.setTitle(string.get(position + 1));
			}
			else
			{
				mif_context = null;
			}

			// /// [information] /////
			position = string.indexOf(INFORMATION_TAG);
			if (position != -1)
			{
				mif_context.setInformation(string.get(position + 1));
			}
			else
			{
				mif_context = null;
			}

			// /// [album_cover] /////
			position = string.indexOf(ALBUM_TAG);
			if (position != -1)
			{
				mif_context.setAlbumCover(string.get(position + 1));
			}
			else
			{
				mif_context = null;
			}

			// /// [genre] /////
			position = string.indexOf(GENRE_TAG);
			if (position != -1)
			{
				mif_context.setGenre(string.get(position + 1));
			}
			else
			{
				mif_context = null;
			}

			// /// [length] /////
			position = string.indexOf(LENGTH_TAG);
			if (position != -1)
			{
				mif_context.setLength(Integer.valueOf(string.get(position + 1)).intValue());
			}
			else
			{
				mif_context = null;
			}

			// [tempo] //
			position = string.indexOf(TEMPO_TAG);
			if (position != -1)
			{
				mif_context.setTempo(Float.valueOf(string.get(position + 1)).floatValue());
			}
			else
			{
				mif_context = null;
			}

			// /// [scale] /////
			position = string.indexOf(SCALE_TAG);
			if (position != -1)
			{
				mif_context.setScale(string.get(position + 1));
			}
			else
			{
				mif_context = null;
			}
			/*
			 * ///// [time] ///// position = string.indexOf( TIME_TAG );
			 * if(position != -1) { mif_context.setTime(
			 * Integer.valueOf(string.get( position + 1 )).intValue() ); } else
			 * { mif_context = null; }
			 */
			// /// [accent] /////
			position = string.indexOf(ACCENT_TAG);
			if (position != -1)
			{
				Vector<Integer> vector = new Vector<Integer>();

				for (int i = 1;; i++)
				{
					if ((position + i) == string.size())
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					vector.add(Integer.valueOf(string.get(position + i)));
				}
				mif_context.setAccent(vector);
			}
			else
			{
				mif_context = null;
			}

			// /// [chord_progression] /////
			position = string.indexOf(CHORD_PROGRESSION_TAG);
			if (position != -1)
			{
				Vector<JamChordProgressionContext> vector = new Vector<JamChordProgressionContext>();

				int size = string.size();

				for (int i = 1;; i++)
				{
					if ((position + i) >= size)
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					String str = string.get(position + i);

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					int j = 0;

					for (; j < length; j++)
					{
						char ch = str.charAt(j);

						if (ch == AndroidGlobal.TAB)
							break;

						time.append(ch);
					}

					for (j = j + 1; j < length; j++)
					{
						char ch = str.charAt(j);

						chord.append(ch);
					}

					Double time_double = new Double(time.toString());

					JamChordProgressionContext jcpc = new JamChordProgressionContext(time_double.intValue(), chord.toString());

					vector.add(jcpc);

					AndroidString.clear(time);
					AndroidString.clear(chord);
				}

				mif_context.setChordProgression(vector);
			}
			else
			{
				mif_context = null;
			}
			
			
			StringBuilder current_time = new StringBuilder();
			StringBuilder global_volume = new StringBuilder();
			
			// /// [global volume] /////
			position = string.indexOf(GLOBAL_VOLUME);
			if (position != -1)
			{
				Vector<JamGlobalVolumeContext> vector = new Vector<JamGlobalVolumeContext>();

				int size = string.size();

				for (int i = 1;; i++)
				{
					if ((position + i) >= size)
						break;

					if (string.get(position + i).contains("[") == true)
						break;

					String str = string.get(position + i);

					int length = string.get(position + i).length();

					if (length == 0)
						break;

					int j = 0;

					for (; j < length; j++)
					{
						char ch = str.charAt(j);

						if (ch == AndroidGlobal.TAB)
							break;

						current_time.append(ch);
					}

					for (j = j + 1; j < length; j++)
					{
						char ch = str.charAt(j);

						global_volume.append(ch);
					}

					JamGlobalVolumeContext jgvc = 
						new JamGlobalVolumeContext( Integer.parseInt(current_time.toString()), Integer.parseInt(global_volume.toString()));

					vector.add(jgvc);

					AndroidString.clear(current_time);
					AndroidString.clear(global_volume);
				}

				mif_context.setGlobalVolume(vector);
			}
			else
			{
//				mif_context = null;
			}
			
			
		}
		catch (Exception e)
		{
			e.printStackTrace();
			Log.e(DEBUG_TAG, "can't parse MIF file");
		}

		return mif_context;
	}

	/*
	 * public static JamMIFContext parseMIFXMLByAndroidSax( String url ) {
	 * 
	 * final JamMIFContext mif_context = new JamMIFContext();
	 * 
	 * RootElement root = null;
	 * 
	 * URL source = null;
	 * 
	 * try { source = new URL( url ); } catch ( MalformedURLException e ) {
	 * Log.e(DEBUG_TAG, e.getMessage()); e.printStackTrace(); }
	 * 
	 * //<mif> root = new RootElement( "mif" );
	 * 
	 * //<bgm> android.sax.Element bgm = root.getChild( "bgm");
	 * 
	 * //<mif><bgm><artist> bgm.getChild("artist").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_context.setArtist( body ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * //<mif><bgm><title> bgm.getChild("title").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_context.setTitle( body ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * //<mif><bgm><album_cover>
	 * bgm.getChild("album_cover").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_context.setAlbumCover( body ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * //<mif><bgm><genre> bgm.getChild("genre").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_context.setGenre( body ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * //<mif><bgm><length> bgm.getChild("length").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_context.setLength( Integer.valueOf( body) ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * //<mif><bgm><tempo> bgm.getChild("tempo").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_context.setTempo( Float.valueOf( body) ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * //<mif><bgm><scale> bgm.getChild("scale").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_context.setScale( body ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * //<mif><bgm><time> bgm.getChild("time").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_context.setTime( Integer.valueOf( body)); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * final Vector<Integer> accent_vector = new Vector<Integer>();
	 * 
	 * //<mif><bgm><accent> for(int i = 1; i < 10;i++) { setAccent( bgm,
	 * "accent", "a"+String.valueOf(i), accent_vector); }
	 * 
	 * //<mif><bgm><chord_progression> android.sax.Element chord_progression_tag
	 * = bgm.getChild("chord_progression"); final
	 * Vector<JamChordProgressionContext> chord_vector = new
	 * Vector<JamChordProgressionContext>();
	 * 
	 * for(int i = 0; i < 127; i++) { //
	 * setChordProgressionT(chord_progression_tag,"t"+String.valueOf(i)); //
	 * setChordProgressionC(chord_progression_tag, "c"+String.valueOf(i));
	 * 
	 * // chord_vector.add( new
	 * JamChordProgressionContext(Integer.valueOf(time).intValue(), chord) ); }
	 * 
	 * AndroidXML.parseXMLByAndroidSAXAtURL( source, root );
	 * 
	 * return mif_context; }
	 * 
	 * private static android.sax.Element setAccent(android.sax.Element element,
	 * String first, String second, final Vector<Integer> vector) {
	 * android.sax.Element ele = element.requireChild( first ).requireChild(
	 * second );
	 * 
	 * ele.setTextElementListener( new TextElementListener() { public void
	 * end(String body) { vector.add(new Integer(body)); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * return ele;
	 * 
	 * }
	 * 
	 * private static String setChordProgressionT(android.sax.Element element,
	 * String first ) { /* android.sax.Element ele = element.getChild( first );
	 * 
	 * if( ele != null) { ele.setTextElementListener( new TextElementListener()
	 * { public void end(String body) { }
	 * 
	 * public void start(Attributes attributes) {} }); } else return null;
	 * 
	 * return null;
	 * 
	 * }
	 * 
	 * 
	 * 
	 * public static JamMIFContext parseMIFXMLBySAX( String url ) {
	 * JamMIFContext mif_context = new JamMIFContext();
	 * 
	 * MIFXMLHandler handler = new MIFXMLHandler();
	 * 
	 * URL source = null;
	 * 
	 * try { source = new URL( url ); } catch ( MalformedURLException e ) {
	 * Log.e(DEBUG_TAG, e.getMessage()); e.printStackTrace(); }
	 * 
	 * AndroidXML.parseXMLBySAXAtURL( source, handler );
	 * 
	 * return mif_context; }
	 * 
	 * 
	 * public static JamConfigContext parseJamConfigXmlByAndroidSax( String url
	 * ) { final JamConfigContext jam_config = new JamConfigContext();
	 * 
	 * final Vector<String> path_vector = new Vector<String>();
	 * 
	 * final Vector<String> bgm_vector = new Vector<String>();
	 * 
	 * final Vector<String> mif_vector = new Vector<String>();
	 * 
	 * RootElement root = null;
	 * 
	 * URL source = null;
	 * 
	 * try { source = new URL( url ); } catch ( MalformedURLException e ) {
	 * Log.e(DEBUG_TAG, e.getMessage()); e.printStackTrace(); }
	 * 
	 * root = new RootElement( "jam" );
	 * 
	 * android.sax.Element config = root.getChild( "config");
	 * 
	 * config.getChild("project").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * jam_config.setProject( body ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * config.getChild("path").getChild("bgm").setTextElementListener( new
	 * TextElementListener() {
	 * 
	 * public void end(String body) { path_vector.add(body); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * config.getChild("bgm").getChild("b1").setTextElementListener( new
	 * TextElementListener() { public void end(String body) { bgm_vector.add(
	 * body ); jam_config.setBGM( bgm_vector ); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * config.getChild( "mif").getChild("m1").setTextElementListener( new
	 * TextElementListener() { public void end(String body) {
	 * mif_vector.add(body); jam_config.setMIF(mif_vector); }
	 * 
	 * public void start(Attributes attributes) {} });
	 * 
	 * final Vector<String> piano_vector = new Vector<String>(); for(int i = 1;
	 * i < 9; i++) { setThreeTag(config, "piano", "o"+String.valueOf(i), "_0c",
	 * piano_vector); setThreeTag(config, "piano", "o"+String.valueOf(i), "_2d",
	 * piano_vector); setThreeTag(config, "piano", "o"+String.valueOf(i), "_4e",
	 * piano_vector); setThreeTag(config, "piano", "o"+String.valueOf(i), "_5f",
	 * piano_vector); setThreeTag(config, "piano", "o"+String.valueOf(i), "_7g",
	 * piano_vector); setThreeTag(config, "piano", "o"+String.valueOf(i), "_9a",
	 * piano_vector); setThreeTag(config, "piano", "o"+String.valueOf(i),
	 * "_11b", piano_vector); } jam_config.setPiano( piano_vector );
	 * 
	 * final Vector<String> classic_guitar_vector = new Vector<String>();
	 * for(int i = 1; i < 5; i++) { setThreeTag(config, "classic_guitar",
	 * "o"+String.valueOf(i), "_0c", classic_guitar_vector); setThreeTag(config,
	 * "classic_guitar", "o"+String.valueOf(i), "_2d", classic_guitar_vector);
	 * setThreeTag(config, "classic_guitar", "o"+String.valueOf(i), "_4e",
	 * classic_guitar_vector); setThreeTag(config, "classic_guitar",
	 * "o"+String.valueOf(i), "_5f", classic_guitar_vector); setThreeTag(config,
	 * "classic_guitar", "o"+String.valueOf(i), "_7g", classic_guitar_vector);
	 * setThreeTag(config, "classic_guitar", "o"+String.valueOf(i), "_9a",
	 * classic_guitar_vector); setThreeTag(config, "classic_guitar",
	 * "o"+String.valueOf(i), "_11b", classic_guitar_vector); }
	 * jam_config.setClassicGuitar( classic_guitar_vector );
	 * 
	 * final Vector<String> elec_bass_vector = new Vector<String>(); for(int i =
	 * 0; i < 4; i++) { setThreeTag(config, "elec_bass", "o"+String.valueOf(i),
	 * "_0c", elec_bass_vector); setThreeTag(config, "elec_bass",
	 * "o"+String.valueOf(i), "_2d", elec_bass_vector); setThreeTag(config,
	 * "elec_bass", "o"+String.valueOf(i), "_4e", elec_bass_vector);
	 * setThreeTag(config, "elec_bass", "o"+String.valueOf(i), "_5f",
	 * elec_bass_vector); setThreeTag(config, "elec_bass",
	 * "o"+String.valueOf(i), "_7g", elec_bass_vector); setThreeTag(config,
	 * "elec_bass", "o"+String.valueOf(i), "_9a", elec_bass_vector);
	 * setThreeTag(config, "elec_bass", "o"+String.valueOf(i), "_11b",
	 * elec_bass_vector); } jam_config.setElecBass( elec_bass_vector);
	 * 
	 * AndroidXML.parseXMLByAndroidSAXAtURL( source, root );
	 * 
	 * return jam_config;
	 * 
	 * }
	 * 
	 * private static void setThreeTag(android.sax.Element tag, String first,
	 * String second, String third, final Vector<String> vector) {
	 * android.sax.Element element = tag.getChild( first).getChild( second
	 * ).getChild(third);
	 * 
	 * if( element != null ) { element.setTextElementListener( new
	 * TextElementListener( ) {
	 * 
	 * public void end(String body) { vector.add(body); }
	 * 
	 * public void start(Attributes attributes) { } }); }
	 * 
	 * return; }
	 * 
	 * public static JamConfigContext parseJamConfigXMLBySAX( String url ) {
	 * JamConfigContext jam_config = new JamConfigContext();
	 * 
	 * MIFXMLHandler handler = new MIFXMLHandler();
	 * 
	 * URL source = null;
	 * 
	 * try { source = new URL( url ); } catch ( MalformedURLException e ) {
	 * Log.e(DEBUG_TAG, e.getMessage()); e.printStackTrace(); }
	 * 
	 * AndroidXML.parseXMLBySAXAtURL( source, handler );
	 * 
	 * return jam_config; }
	 * 
	 * public static JamConfigContext parseJamConfigXMLByDOM( String url ) {
	 * JamConfigContext jam_config = new JamConfigContext();
	 * 
	 * Document document = AndroidXML.parseXMLByDOMAtURL( url );
	 * 
	 * org.w3c.dom.Element root = document.getDocumentElement();
	 * 
	 * NodeList config_node_list = root.getElementsByTagName( "config" );
	 * 
	 * int count = config_node_list.getLength();
	 * 
	 * if( (config_node_list != null) && (count > 0)) { for( int i = 0; i <
	 * count ; i++ ) { Element ele = (Element) config_node_list.item(i);
	 * 
	 * //project tag Element project = (Element) ele.getElementsByTagName(
	 * "project" ).item(0); String project_string =
	 * project.getFirstChild().getNodeValue(); jam_config.setProject(
	 * project_string);
	 * 
	 * 
	 * //mif tag Element mif = (Element) ele.getElementsByTagName( "MIF"
	 * ).item(0); Element _001_mif_ele = (Element) mif.getElementsByTagName(
	 * "_001" ).item(0);
	 * 
	 * Vector<String> mif_vector = new Vector<String>(); String _001_mif_string
	 * = _001_mif_ele.getFirstChild().getNodeValue();
	 * mif_vector.add(_001_mif_string); jam_config.setMIF(mif_vector);
	 * 
	 * 
	 * //piano tag Vector<String> piano_vector = new Vector<String>(); Element
	 * piano = (Element) ele.getElementsByTagName( "PIANO" ).item(0);
	 * 
	 * Element o1 = (Element) piano.getElementsByTagName( "o1" ).item(0);
	 * 
	 * Element _0_C = (Element) o1.getElementsByTagName( "_0_C").item(0);
	 * Element _2_D = (Element) o1.getElementsByTagName( "_2_D").item(0);
	 * Element _4_E = (Element) o1.getElementsByTagName( "_4_E").item(0);
	 * Element _5_F = (Element) o1.getElementsByTagName( "_5_F").item(0);
	 * Element _7_G = (Element) o1.getElementsByTagName( "_7_G").item(0);
	 * Element _9_A = (Element) o1.getElementsByTagName( "_9_A").item(0);
	 * Element _11_B = (Element) o1.getElementsByTagName( "_11_B").item(0);
	 * 
	 * 
	 * piano_vector.add(_0_C.getFirstChild().getNodeValue());
	 * piano_vector.add(_2_D.getFirstChild().getNodeValue());
	 * piano_vector.add(_4_E.getFirstChild().getNodeValue());
	 * piano_vector.add(_5_F.getFirstChild().getNodeValue());
	 * piano_vector.add(_7_G.getFirstChild().getNodeValue());
	 * piano_vector.add(_9_A.getFirstChild().getNodeValue());
	 * piano_vector.add(_11_B.getFirstChild().getNodeValue());
	 * 
	 * Element o2 = (Element) piano.getElementsByTagName( "o2" ).item(0);
	 * 
	 * Element _o2_0_C = (Element) o2.getElementsByTagName( "_0_C").item(0);
	 * Element _o2_2_D = (Element) o2.getElementsByTagName( "_2_D").item(0);
	 * Element _o2_4_E = (Element) o2.getElementsByTagName( "_4_E").item(0);
	 * Element _o2_5_F = (Element) o2.getElementsByTagName( "_5_F").item(0);
	 * Element _o2_7_G = (Element) o2.getElementsByTagName( "_7_G").item(0);
	 * Element _o2_9_A = (Element) o2.getElementsByTagName( "_9_A").item(0);
	 * Element _o2_11_B = (Element) o2.getElementsByTagName( "_11_B").item(0);
	 * 
	 * 
	 * piano_vector.add(_o2_0_C.getFirstChild().getNodeValue());
	 * piano_vector.add(_o2_2_D.getFirstChild().getNodeValue());
	 * piano_vector.add(_o2_4_E.getFirstChild().getNodeValue());
	 * piano_vector.add(_o2_5_F.getFirstChild().getNodeValue());
	 * piano_vector.add(_o2_7_G.getFirstChild().getNodeValue());
	 * piano_vector.add(_o2_9_A.getFirstChild().getNodeValue());
	 * piano_vector.add(_o2_11_B.getFirstChild().getNodeValue());
	 * 
	 * 
	 * Element o3 = (Element) piano.getElementsByTagName( "o3" ).item(0);
	 * 
	 * Element _o3_0_C = (Element) o3.getElementsByTagName( "_0_C").item(0);
	 * Element _o3_2_D = (Element) o3.getElementsByTagName( "_2_D").item(0);
	 * Element _o3_4_E = (Element) o3.getElementsByTagName( "_4_E").item(0);
	 * Element _o3_5_F = (Element) o3.getElementsByTagName( "_5_F").item(0);
	 * Element _o3_7_G = (Element) o3.getElementsByTagName( "_7_G").item(0);
	 * Element _o3_9_A = (Element) o3.getElementsByTagName( "_9_A").item(0);
	 * Element _o3_11_B = (Element) o3.getElementsByTagName( "_11_B").item(0);
	 * 
	 * piano_vector.add(_o3_0_C.getFirstChild().getNodeValue());
	 * piano_vector.add(_o3_2_D.getFirstChild().getNodeValue());
	 * piano_vector.add(_o3_4_E.getFirstChild().getNodeValue());
	 * piano_vector.add(_o3_5_F.getFirstChild().getNodeValue());
	 * piano_vector.add(_o3_7_G.getFirstChild().getNodeValue());
	 * piano_vector.add(_o3_9_A.getFirstChild().getNodeValue());
	 * piano_vector.add(_o3_11_B.getFirstChild().getNodeValue());
	 * 
	 * Element o4 = (Element) piano.getElementsByTagName( "o4" ).item(0);
	 * 
	 * Element _o4_0_C = (Element) o4.getElementsByTagName( "_0_C").item(0);
	 * Element _o4_2_D = (Element) o4.getElementsByTagName( "_2_D").item(0);
	 * Element _o4_4_E = (Element) o4.getElementsByTagName( "_4_E").item(0);
	 * Element _o4_5_F = (Element) o4.getElementsByTagName( "_5_F").item(0);
	 * Element _o4_7_G = (Element) o4.getElementsByTagName( "_7_G").item(0);
	 * Element _o4_9_A = (Element) o4.getElementsByTagName( "_9_A").item(0);
	 * Element _o4_11_B = (Element) o4.getElementsByTagName( "_11_B").item(0);
	 * 
	 * piano_vector.add(_o4_0_C.getFirstChild().getNodeValue());
	 * piano_vector.add(_o4_2_D.getFirstChild().getNodeValue());
	 * piano_vector.add(_o4_4_E.getFirstChild().getNodeValue());
	 * piano_vector.add(_o4_5_F.getFirstChild().getNodeValue());
	 * piano_vector.add(_o4_7_G.getFirstChild().getNodeValue());
	 * piano_vector.add(_o4_9_A.getFirstChild().getNodeValue());
	 * piano_vector.add(_o4_11_B.getFirstChild().getNodeValue());
	 * 
	 * Element o5 = (Element) piano.getElementsByTagName( "o5" ).item(0);
	 * 
	 * Element _o5_0_C = (Element) o5.getElementsByTagName( "_0_C").item(0);
	 * Element _o5_2_D = (Element) o5.getElementsByTagName( "_2_D").item(0);
	 * Element _o5_4_E = (Element) o5.getElementsByTagName( "_4_E").item(0);
	 * Element _o5_5_F = (Element) o5.getElementsByTagName( "_5_F").item(0);
	 * Element _o5_7_G = (Element) o5.getElementsByTagName( "_7_G").item(0);
	 * Element _o5_9_A = (Element) o5.getElementsByTagName( "_9_A").item(0);
	 * Element _o5_11_B = (Element) o5.getElementsByTagName( "_11_B").item(0);
	 * 
	 * piano_vector.add(_o5_0_C.getFirstChild().getNodeValue());
	 * piano_vector.add(_o5_2_D.getFirstChild().getNodeValue());
	 * piano_vector.add(_o5_4_E.getFirstChild().getNodeValue());
	 * piano_vector.add(_o5_5_F.getFirstChild().getNodeValue());
	 * piano_vector.add(_o5_7_G.getFirstChild().getNodeValue());
	 * piano_vector.add(_o5_9_A.getFirstChild().getNodeValue());
	 * piano_vector.add(_o5_11_B.getFirstChild().getNodeValue());
	 * 
	 * jam_config.setPiano( piano_vector );
	 * 
	 * 
	 * Element classic_guitar = (Element) ele.getElementsByTagName(
	 * "CLASSIC_GUITAR" ).item(0); Element elec_bass = (Element)
	 * ele.getElementsByTagName( "ELEC_BASS" ).item(0);
	 * 
	 * 
	 * 
	 * } }
	 * 
	 * return jam_config; }
	 * 
	 * }
	 * 
	 * 
	 * class MIFXMLHandler extends DefaultHandler { private boolean artist =
	 * false; private boolean chord_progression = false;
	 * 
	 * private Vector<JamChordProgressionContext> chord = new
	 * Vector<JamChordProgressionContext>();
	 * 
	 * private JamMIFContext mif = new JamMIFContext();
	 * 
	 * public void startElement( String uri, String localName, String qName,
	 * Attributes atts ) { if(localName == "ARTIST") { this.artist = true; }
	 * if(localName == "CHORD_PROGRESSION") { this.chord_progression = true; } }
	 * 
	 * public void endElement( String uri, String localName, String qName ) {
	 * 
	 * }
	 * 
	 * public void characters( char[] chars, int start, int leng ) { if( artist
	 * == true) { mif.setArtist( new String( chars) ); this.artist = false; }
	 * 
	 * if( this.chord_progression == true ) { // mif.setChordProgression( ) }
	 * 
	 * AndroidString.clear( chars ); }
	 */
}
